home *** CD-ROM | disk | FTP | other *** search
/ The X-Philes (2nd Revision) / The X-Philes Number 1 (1995).iso / xphiles / psion / spr.fmt < prev    next >
Text File  |  1995-03-31  |  16KB  |  372 lines

  1. PSIONICS FILE - SPR.FMT
  2. =======================
  3. Format of Spreadsheet files
  4. Last modified 1994-03-01
  5. ===========================
  6.  
  7. This document describes the layout of SPR files for the SH3 spreadsheet.
  8.  
  9. A data file (also called a database file) begins with a 22 byte header of the
  10. following form:
  11.   Offset  0 (cstr): "SPREADSHEET"
  12.   Offset 16 (word): format version number
  13.   Offset 18 (word): offset value (meaning unknown)
  14.   Offset 20 (word): OPL runtime version number
  15.  
  16. The version numbers and offset value are all zero.
  17.  
  18. The rest of the file consists of records. All records have the form:
  19.   Offset  0 (word): type of record
  20.   Offset  2 (word): size of data portion in bytes (L)
  21.   Offset  4 to L+3: data portion
  22.  
  23. Unless stated otherwise, records may appear in any order. Record types 11 and
  24. 12 should not appear in Series 3 spreadsheets - they were used by the MC. Types
  25. 13 onwards are new in the Series 3.
  26.  
  27. Unless stated otherwise, a cell reference is two words - column then row - and
  28. a range reference is four words - left, top, right, bottom, in that order.
  29. Each word is intepreted as follows. If the word is N, then:
  30.       0 <= N <= $1FFF: Nth row or column (so 0 is row 1 or column A)
  31.            N =  $8000: this row or column
  32.   $8000 <  N <  $9FFF: row N-$8000 below or column N-$8000 to right
  33.   $E000 <  N <= $FFFF: row $10000-N above or column $10000-N to left
  34. Values with the top bit set are only permitted in formulae. In some other
  35. circumstances a reference containing all $FFFF values is used for "none".
  36.  
  37.  
  38. Record type 1 holds formulae. A formula must come before any cell (record type
  39. 2) that accesses it, and the relative order of type 1 records should be
  40. preserved. The record takes the form:
  41.   Offset  0 (word): number of records using this formula
  42.   Offset  2 (byte): length of formula (F)
  43.   Offset  3 to F+2: formula
  44.  
  45. A formula is stored using a Reverse Polish notation. In other words, to
  46. evaluate a formula, start with an empty stack, and then scan the formula in
  47. order; when finding an operand, push it on the stack, while when finding an
  48. operator, take its arguments off the stack, apply it, and push the answer on
  49. the stack.
  50.  
  51. Operators are represented by single bytes:
  52.   1 = <      5 = <>     9 = *     13 = -     17 = &
  53.   2 = <=     6 = =     10 = /     14 = NOT
  54.   3 = >      7 = +     11 = **    15 = AND
  55.   4 = >=     8 = -     12 = +     16 = OR
  56. (all take two operands except 12 to 14; 17 is string concatenate).
  57.  
  58. Delimiters are represented by single bytes:
  59.   18 = (     These are not strictly needed, but allow the original
  60.   19 = )     entered formula to be recreated for editing
  61.   20 = ,
  62.   @The above 3 need testing@
  63.   21 = end of formula
  64.  
  65. Operands are represented by a byte followed by the value of the operand:
  66.   22 = real (8 bytes)
  67.   23 = word (2 bytes)
  68.   24 = qstr
  69.   25 = cell reference
  70.   26 = range reference
  71.  
  72. Functions with no arguments or a fixed list of arguments are represented by
  73. single bytes; the operands are treated exactly as for operators. In the
  74. following list, the arguments are shown as "n" for numeric, "s" for string,
  75. and "r" for range.
  76.  
  77.   27 ERR              55 LOG(n)           83 STRING(n,n)
  78.   28 FALSE            56 LOWER(s)         84 CTERM(n,n)
  79.   29 NA               57 MINUTE(n)        85 DATE(n,n)
  80.   30 PI               58 MONTH(n)         86 DAVG(r,n,r)
  81.   31 RAND             59 N(r)             87 DCOUNT(r,n,r)
  82.   32 NOW              60 PROPER(s)        88 DMAX(r,n,r)
  83.   33 TRUE             61 ROWS(r)          89 DMIN(r,n,r)
  84.   34 ABS(n)           62 S(r)             90 DSTD(r,n,r)
  85.   35 ACOS(n)          63 SECOND(n)        91 DSUM(r,n,r)
  86.   36 ASIN(n)          64 SIN(n)           92 DVAR(r,n,r)
  87.   37 AT(s)            65 SQRT(n)          93 FIND(s,s,n)
  88.   38 ATAN(n)          66 TAN(n)           94 FV(n,n,n)
  89.   39 CELLPOINTER(n)   67 TIMEVALUE(s)     95 HLOOKUP(n,r,n)
  90.   40 CHAR(n)          68 TRIM(s)          96 IF(n,n,n)
  91.   41 CODE(s)          69 UPPER(s)         97 INDEX(r,n,n)
  92.   42 COLS(r)          70 VALUE(s)         98 MID(s,n,n)
  93.   43 COS(n)           71 YEAR(n)          99 PMT(n,n,n)
  94.   44 DATEVALUE(s)     72 ATAN2(n,n)      100 PV(n,n,n)
  95.   45 DAY(n)           73 CELL(n,r)       101 RATE(n,n,n)
  96.   46 EXP(n)           74 EXACT(s,s)      102 SIN(n)
  97.   47 HOUR(n)          75 IRR(n,n)        103 TERM(n,n,n)
  98.   48 INT(n)           76 LEFT(s,n)       104 TIME(n,n,n)
  99.   49 ISERR(r)         77 MOD(n,n)        105 VLOOKUP(r,n,n)
  100.   50 ISNA(r)          78 NPV(n,n)        106 DDB(n,n,n,n)
  101.   51 ISNUM(r)         79 --------        107 REPLACE(s,n,n,s)
  102.   52 ISSTR(r)         80 REPEAT(s,n)     108 SYD(n,n,n,n)
  103.   53 LEN(s)           81 RIGHT(s,n)
  104.   54 LN(n)            82 ROUND(n,n)
  105.  
  106. Functions with a variable list of arguments are more complex. The call is
  107. built up as follows:
  108.   - a START byte
  109.   - the arguments
  110.   - an END byte
  111.   - the number of arguments (a byte)
  112. The arguments are just placed in order. An argument is either:
  113.   - the value of the argument, followed by an ARG byte
  114.   - a RANGE byte followed by a range reference
  115. Note that all arguments other than ranges, including cell references, work
  116. by evaluating the argument in the normal way; ARG in effect says to pop the
  117. next argument off the stack.
  118.  
  119. The values of the four special bytes differ for each function:
  120.  
  121.                 START    END     ARG    RANGE
  122.     AVG()        120     112     136     128
  123.     CHOOSE()     121     113     137     129
  124.     COUNT()      122     114     138     130
  125.     MAX()        123     115     139     131
  126.     MIN()        124     116     140     132
  127.     STD()        125     117     141     133
  128.     SUM()        126     118     142     134
  129.     VAR()        127     119     143     135
  130.  
  131.  
  132. Record type 2 describes a cell. It has the following format:
  133.   Offset  0 to   3: cell reference
  134.   Offset  4 (byte): flags:
  135.     Bits 0 to 2: cell contents type:
  136.       0 = blank
  137.       1 = real constant
  138.       2 = text constant
  139.       3 = word constant
  140.       5 = real formula
  141.       6 = text formula
  142.     Bits 3 to 4: text alignment: 0 = repeat, 1 = left, 2 = right, 3 = centre
  143.     Bit 5:       set for left aligned numerics, clear for right aligned
  144.     Bit 6:       set if the cell has changed since the last recalculation
  145.     Bit 7:       should not be altered, used by natural order sort
  146.   Offset  5 (byte): format
  147.     Bits 0 to 3: number of digits in display format
  148.       For special formats, this selects the special format:
  149.          0 = bargraph,  1 = general, 5 = show formulae, 6 = hidden, 9 = date,
  150.         11 = time,     15 = default
  151.     Bits 4 to 6: display format: 0 = fixed,      1 = scientific,  2 = currency,
  152.                                  3 = percentage, 4 = triad/comma, 7 = special
  153.     Bit 7:       set if the cell is protected
  154.  
  155. This is then followed by a value block and then optionally a font byte.
  156. The value block depends on the contents type:
  157.   Type 0 (blank) has no value block
  158.   Type 1 (real constant):
  159.     Offset  6 (real): value
  160.   Type 2 (text constant):
  161.     Offset  6 (qstr): value
  162.   Type 3 (word constant):
  163.     Offset  6 (word): value
  164.   Type 5 (real formula):
  165.     Offset  6 (word): index of formula
  166.     Offset  8 (real): current value
  167.   Type 5 (text formula):
  168.     Offset  6 (word): index of formula
  169.     Offset  8 (qstr): current value
  170. The index of a formula is its position in the set of type 1 records. So 0
  171. means the first type 1 record, 1 the second type 1 record, and so on.
  172.  
  173. The font byte is simply a number from 0 to 3, giving the font of the cell.
  174.  
  175.  
  176. Record type 3 describes column widths, and appears for each column not of the
  177. default width. The record takes the form:
  178.   Offset  0 (byte): column number
  179.   Offset  1 (byte): width
  180.  
  181.  
  182. Record type 4 describes the default column width:
  183.   Offset  0 (word): default width
  184.  
  185.  
  186. Record type 5 holds general status information:
  187.   Offset  0 (byte): flags
  188.     Bit 0:       set if automatic recalculate is on
  189.     Bit 1:       set if protection override is on
  190.     Bit 2:       set if a cell has been deleted since the last recalculation
  191.     Bit 3:       set if table recalculation is on
  192.     Bits 4 to 7: unused, always zero
  193.   Offset  1 (byte): unused, always zero
  194.   Offset  2 (byte): default numeric display format
  195.   Offset  3 (byte): default alignment for new cells
  196. The default numeric display format uses the same encoding as cells do, with
  197. bit 7 always being zero. The default alignment uses the same encoding as the
  198. flags of a cell, with bits 0 to 2, 6, and 7 always being zero.
  199.  
  200.  
  201. Record type 6 holds information about the current state of the display:
  202.   Offset  0 to   7: range reference of titles
  203.   Offset  8 to  11: cell reference of top left displayed cell excluding titles
  204.   Offset 12 to  19: range reference of selected range
  205.   Offset 20 to  23: cell reference of cursor
  206.   Offset 24 (byte): non-zero if grid lines are to be displayed, zero if not
  207.   Offset 25 (byte): zero if zero values are to be displayed, non-zero if not
  208.  
  209.  
  210. Record type 7 describes a named cell or range:
  211.   Offset  0 (cstr): name
  212.   Offset 16 to  23: range reference
  213.   Offset 24 (word): type: 25 = cell, 26 = range
  214.  
  215.  
  216. Record type 8 describes a range to be offered for selective printing:
  217.   Offset  0 to   7: range reference
  218. There may be any number of such records.
  219.  
  220.  
  221. Record type 9 describes the criterion and database ranges for the database
  222. commands. If this record occurs more than once, the last one will be used.
  223. The record takes the form:
  224.   Offset  0 to   7: criterion range reference
  225.   Offset  8 to  15: database range reference
  226.  
  227.  
  228. Record type 10 describes information for the table commands. If this record
  229. occurs more than once, the last one will be used. The record takes the form:
  230.   Offset  0 to   7: table range reference
  231.   Offset  8 to  11: input cell 1 reference
  232.   Offset 12 to  15: input cell 2 reference, or $FFFF if only one input cell
  233.  
  234.  
  235. Record type 11 describes the print setup. It should not appear in Series 3
  236. spreadsheets - it was used by the MC. The record takes the form:
  237.   Offset  0 (byte): flags
  238.     Bit 0:       set if values are shown, clear if formulae are shown
  239.     Bit 1:       set if hidden cells are shown
  240.     Bit 2:       set if column separators are shown
  241.     Bit 3:       set if headers are shown
  242.     Bits 4 to 7: unused, always zero
  243.   Offset  1 (byte): unused, always zero
  244.  
  245.  
  246. Record type 12 describes the printer font. It should not appear in Series 3
  247. spreadsheets - it was used by the MC. The record takes the form:
  248.   Offset  0 (byte): flags
  249.     Bit 0:       set for bold
  250.     Bits 1 to 2: unused, always zero
  251.     Bit 3:       set for double height
  252.     Bits 4 to 7: unused, always zero
  253.   Offset  1 (byte): unused, always zero
  254.   Offset  2 to  17: font name
  255.  
  256.  
  257. Record type 13 describes a graph (see Psion-/):
  258.   Offset   0 (cstr): name (see Psion-E)
  259.   Offset  16 to  23: range reference for data range A (see Psion-R)
  260.   Offset  24 to  31: range reference for data range B
  261.   Offset  32 to  39: range reference for data range C
  262.   Offset  40 to  47: range reference for data range D
  263.   Offset  48 to  55: range reference for data range E
  264.   Offset  56 to  63: range reference for data range F
  265.   Offset  64 to  71: range reference for data range X
  266.   Offset  72 to  79: range reference for labels for range A (see Psion-B)
  267.   Offset  80 to  87: range reference for labels for range B
  268.   Offset  88 to  95: range reference for labels for range C
  269.   Offset  96 to 103: range reference for labels for range D
  270.   Offset 104 to 111: range reference for labels for range E
  271.   Offset 112 to 119: range reference for labels for range F
  272.   Offset 120 (byte): format of range A
  273.   Offset 121 (byte): format of range B
  274.   Offset 122 (byte): format of range C
  275.   Offset 123 (byte): format of range D
  276.   Offset 124 (byte): format of range E
  277.   Offset 125 (byte): format of range F
  278.     All the formats (see Psion-L) are encoded in the same way:
  279.     Bit 0:       set if lines are shown
  280.     Bit 1:       set if symbols are shown
  281.     Bits 2 to 7: unused, always zero
  282.   Offset 126 (byte): alignment of label range A
  283.   Offset 127 (byte): alignment of label range B
  284.   Offset 128 (byte): alignment of label range C
  285.   Offset 129 (byte): alignment of label range D
  286.   Offset 130 (byte): alignment of label range E
  287.   Offset 131 (byte): alignment of label range F
  288.     Label range alignments (see Psion-B) are:
  289.     0 = centre, 1 = right, 2 = below, 3 = left, 4 = above
  290.   Offset 132 (byte): x-axis scaling (see Psion-A)
  291.     Bit 0:       set for manual upper range, clear for automatic upper range
  292.     Bit 1:       set for manual upper range, clear for automatic upper range
  293.     Bits 2 to 7: unused, always zero
  294.   Offset 133 (byte): x-axis format (see Psion-A), as for cell format (record
  295.     type 2) but with bit 7 always zero
  296.   Offset 134 (real): x-axis lower limit (see Psion-A)
  297.   Offset 142 (real): x-axis upper limit (see Psion-A)
  298.   Offset 150 (byte): y-axis scaling, as for x-axis
  299.   Offset 151 (byte): y-axis format, as for x-axis
  300.   Offset 152 (real): y-axis lower limit, as for x-axis
  301.   Offset 160 (real): y-axis upper limit, as for x-axis
  302.   Offset 168 (byte): graph type (see Psion-F)
  303.     0 = scatter, 1 = bar, 2 = pie, 4 = line, 5 = stack-bar
  304.   Offset 169 (byte): grid flags (see Psion-F)
  305.     Bit 0:       set if horizontal grid lines visible
  306.     Bit 1:       set if vertical   grid lines visible
  307.     Bits 2 to 7: unused, always zero
  308.   Offset 170 (byte): colour, encoding unknown
  309.   Offset 171 (byte): ranges enabled (see Psion-R)
  310.     Bits 0 to 5: set if ranges A to F respectively are enabled
  311.     Bit 6:       set if range X is enabled
  312.     Bit 7:       unused, always zero
  313.   Offset 172 (byte): range labels enabled (see Psion-B)
  314.     Bits 0 to 5: set if ranges A to F respectively are enabled
  315.     Bits 6 to 7: unused, always zero
  316.   Offset 173 (byte): other flags
  317.     Bits 0 and 1: font size: 0 = auto, 1 = small, 2 = big (see Psion-F)
  318.     Bits 2 and 3: pie labels: 0 = none, 1 = percent, 2 = values (see Psion-F)
  319.     Bit 4:        set for 3D graphs (see Psion-F)
  320.     Bit 5:        set if Y-axis title enabled (see Psion-I)
  321.     Bit 6:        set if X-axis title enabled (see Psion-I)
  322.     Bit 7:        set if titles enabled (see Psion-T)
  323.   Offset 174 (word): unused
  324.  
  325. At offset 176 onwards are 10 cstrs. These are, in order:
  326.   title first line
  327.   title second line
  328.   x-axis title
  329.   y-axis title
  330.   range A legend
  331.   range B legend
  332.   range C legend
  333.   range D legend
  334.   range E legend
  335.   range F legend
  336. The titles are limited to 40 characters, and the range legends to 20.
  337.  
  338.  
  339. Record type 14 indicates which graph is current:
  340.   Offset  0 (word): index of current graph
  341. (the index is the count of type 13 records, so 0 means the first type 13
  342. record in the file, and so on).
  343.  
  344.  
  345. Record type 15 describes the fonts used. It consists of 4 font records, which
  346. correspnd to fonts 1 to 4. Each font record has the format:
  347.   Offset  0 to  5: unknown
  348.  
  349.  
  350. Record type 16 holds information about printer set-up, and is identical to
  351. record type 2 in Word files (see WORD.FMT).
  352.  
  353.  
  354. Record type 17 describes the printer driver. It is identical to record type 2
  355. in Word files:
  356.   Offset  0 (byte): printer driver model number
  357.   Offset  1 (cstr): printer driver library
  358. A printer driver library can support several similar printers; the model number
  359. specifies which is selected.
  360.  
  361.  
  362. Record types 18 and 19 hold the header and footer text respectively as a cstr.
  363.  
  364.  
  365. Record type 20 holds additional information about the screen. It will be
  366. ignored if it does not directly preceed record type 6. It has the format:
  367.   Offset  0 (byte): flags
  368.     Bit 0:       set if grid labels are shown
  369.     Bit 1:       set if small font is in use
  370.     Bits 2 to 7: unused, always zero
  371.   Offset  1 (byte): ignored (always zero)
  372.